package com.wzz.controller;

import com.aliyun.oss.common.utils.DateUtil;
import com.wzz.entity.ReqExam;
import com.wzz.entity.Snatch;
import com.wzz.service.ReqExamService;
import com.wzz.service.SnatchService;
import com.wzz.utils.CertificateUtil.DateTimeUtil;
import com.wzz.utils.JwtUtils;
import com.wzz.utils.RedisUtil;
import com.wzz.vo.CommonResult;
import com.wzz.vo.TokenVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.apache.http.client.utils.DateUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;


@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/snatch")
public class SnatchController {
    private final SnatchService snatchService;
    private final RedisUtil redisUtil;


    @PostMapping("/addSnatch")
    public CommonResult<Void> addSnatch(@RequestBody @Valid Snatch snatch) {
        snatch.setCreatedate(DateTimeUtil.DateToString(new Date()));
        snatchService.addSnatch(snatch);
        redisUtil.sSetAndTime(snatch.getExamid()+snatch.getQuestionid()+"time",10,"1");
        return CommonResult.<Void>builder().build();
    }

    @GetMapping("/getAllSnatch")
    @ApiOperation("获取请求数据列表)")
    @ApiImplicitParams({})
    public CommonResult<List<Snatch>> getAllSnatch() {
        return CommonResult.<List<Snatch>>builder()
                .data(snatchService.getSnatchs())
                .build();
    }


    @PostMapping("/updateSnatch")
    @ApiOperation("更新")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Snatch", value = "请求状态", required = true, dataType = "reqExam", paramType = "body")
    })
    public CommonResult<Void> updateNotice(@RequestParam(required = true, name = "id") Integer id,@RequestParam(required = true, name = "flag") String flag) {
        snatchService.updateSnatch(id,flag);
        return CommonResult.<Void>builder().build();
    }
}
